﻿using Microsoft.EntityFrameworkCore;

namespace EFCoreLenarn
{
    public class MySqlDbContext:DbContext
    {
        public DbSet<Book> Books { get; set; }
        public DbSet<Author> Authors { get; set; }

        public DbSet<Article> Articles { get; set; }

        public DbSet<Comment> Comments { get; set; }

        public DbSet<User> Users { get; set; }

        public DbSet<Leave> Leaves { get; set; }

        public DbSet<Order> Orders { get; set; }
        public DbSet<Delivery> Deliveries { get; set; }

        public DbSet<Student> Students { get; set; }
        public DbSet<Teacher> Teachers { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            string conn = "server=localhost;database=demo1;user=root;password=123456;";
            optionsBuilder.UseMySql(conn, new MySqlServerVersion(new Version(8, 6, 20)));
            optionsBuilder.LogTo(Console.WriteLine);

            // 打印执行的SQL语句
            optionsBuilder.LogTo(Console.WriteLine);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
            // 当某个类需要配置忽略属性时候需要在这里配置
            //modelBuilder.Entity<Book>().Ignore(b => b.Name2);
        }
    }
}
